package com.util.KeyInfo;

import com.util.PublicUtil;

import javax.sql.DataSource;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: Ryan lee
 * Date: Mar 15, 2008
 * Time: 7:06:34 PM
 * To change this template use File | Settings | File Templates.
 */
public class KeyGenerator {
    private int poolSize = 5;
    private HashMap<String, KeyInfo> keyList = new HashMap<String, KeyInfo>(50);

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    private DataSource dataSource;


    public  int getPoolSize() {
        return poolSize;
    }

    public  void setPoolSize(int poolSize) {
        this.poolSize = poolSize;
    }

    public synchronized long getNextKey(String KeyName)  {
        KeyInfo keyinfo;
        KeyName = KeyName.toUpperCase();
        if (keyList.containsKey(KeyName)) {
            keyinfo = keyList.get(KeyName);
        } else {
            keyinfo = new KeyInfo(poolSize, KeyName, dataSource);
            keyList.put(KeyName, keyinfo);
        }
        return keyinfo.getNextKey();
    }




}
